//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Diagnostics.Contracts;
using System.IO;

namespace OpenLS.Spreadsheet.Formats.Biff.Records
{
    internal class RrTabIdRecord: BiffRecord
    {
        private ushort[] tabIds;
        protected override void ReadContent(BiffReaderContext context, int length)
        {
            Contract.Assert(length%2 == 0);
            tabIds = new ushort[length / 2];
            for (int i = 0; i < tabIds.Length; i++)
                tabIds[i] = context.ReadUInt16();
        }

        internal override BiffRecordType RecordType
        {
            get { return BiffRecordType.RRTabId ; }
        }

        internal override void WriteContent(BiffWriterWorkbookContext context)
        {
            if (context.Workbook != null)
            {
                for (ushort i = 1; i <= context.Workbook.Sheets.Count; i++)
                    context.WriteUInt16(i);
                return;
            }
            foreach (var tabId in tabIds)
            {
                context.Write(tabId);
            }
        }
    }
}